package com.sidianzhong.sdz.controller;



import com.sidianzhong.sdz.model.WebAequipmentgroup;
import com.sidianzhong.sdz.service.WebAequipmentgroupService;
import com.sidianzhong.sdz.utils.PageInfo;
import com.sidianzhong.sdz.utils.ResultModel;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import java.util.*;

/**
 * Created by hxg on 2016/10/06.
 */

@Api(description = "微波设备")
@RestController
public class WebAequipmentgroupController {

    @Autowired
    WebAequipmentgroupService webAequipmentgroupService;

    @Autowired
    HttpServletResponse response;

    @ApiOperation(value = "根据id查询微波设备")
    @RequestMapping(value = "/getWebAequipmentgroupById",
                    method = {RequestMethod.GET},
                    produces = "application/json;charset=UTF-8")
    @ResponseBody
    public Object getWebAequipmentgroupById(
            HttpServletRequest request,
            @RequestParam(value = "web_aequipmentgroup_id") Integer id
    ) {
            WebAequipmentgroup item = webAequipmentgroupService.get(id);
            if (null == item) {
                return new ResponseEntity<>(ResultModel.error(item), HttpStatus.OK);
            }

             return new ResponseEntity<>(ResultModel.ok(item), HttpStatus.OK);

    }

    @ApiOperation(value = "查询微波设备")
    @RequestMapping(value = "/web_aequipmentgroups",
                    method = { RequestMethod.GET },
                    produces = "application/json;charset=UTF-8")
    @ResponseBody
    public Object getWebAequipmentgroups(
            HttpServletRequest request,
            @RequestParam(value = "pageNum", required = false, defaultValue = "1") Integer pageNum,
            @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize,
            @RequestParam(value = "sortItem", required = false, defaultValue = "id") String sortItem,
            @RequestParam(value = "sortOrder", required = false, defaultValue = "desc") String sortOrder,
            @RequestParam(value = "sitename", required = false) String sitename,
            @RequestParam(value = "equipmenttypekey", required = false) String equipmenttypekey,
            @RequestParam(value = "equipmentname", required = false) String equipmentname,
            @RequestParam(value = "equipmentkey", required = false) String equipmentkey,
            @RequestParam(value = "status", required = false) String status,
            @RequestParam(value = "equipmentip", required = false) String equipmentip,
            @RequestParam(value = "agreementtype", required = false) String agreementtype,
            @RequestParam(value = "bindtype", required = false) String bindtype,
            @RequestParam(value = "equipmentport", required = false) String equipmentport,
            @RequestParam(value = "equipmentid", required = false) String equipmentid,
            @RequestParam(value = "tablename", required = false) String tablename,
            @RequestParam(value = "itemname", required = false) String itemname,
            @RequestParam(value = "warmingdata", required = false) String warmingdata,
            @RequestParam(value = "maintransmittername", required = false) String maintransmittername,
            @RequestParam(value = "maintransmitterkey", required = false) String maintransmitterkey,
            @RequestParam(value = "sparetransmittername", required = false) String sparetransmittername,
            @RequestParam(value = "sparetransmitterkey", required = false) String sparetransmitterkey,
            @RequestParam(value = "maintransmitterpowertype", required = false) String maintransmitterpowertype,
            @RequestParam(value = "sparetransmitterpowertype", required = false) String sparetransmitterpowertype,
            @RequestParam(value = "ifmonitor", required = false) String ifmonitor,
            @RequestParam(value = "equipmentmodel", required = false) String equipmentmodel,
            @RequestParam(value = "valueself", required = false) String valueself
    ) {
        WebAequipmentgroup item = new WebAequipmentgroup();
        if( sitename != null ){
            item.setSitename(sitename);
        }
        if( equipmenttypekey != null ){
            item.setEquipmenttypekey(equipmenttypekey);
        }
        if( equipmentname != null ){
            item.setEquipmentname(equipmentname);
        }
        if( equipmentkey != null ){
            item.setEquipmentkey(equipmentkey);
        }
        if( status != null ){
            item.setStatus(status);
        }
        if( equipmentip != null ){
            item.setEquipmentip(equipmentip);
        }
        if( agreementtype != null ){
            item.setAgreementtype(agreementtype);
        }
        if( bindtype != null ){
            item.setBindtype(bindtype);
        }
        if( equipmentport != null ){
            item.setEquipmentport(equipmentport);
        }
        if( equipmentid != null ){
            item.setEquipmentid(equipmentid);
        }
        if( tablename != null ){
            item.setTablename(tablename);
        }
        if( itemname != null ){
            item.setItemname(itemname);
        }
        if( warmingdata != null ){
            item.setWarmingdata(warmingdata);
        }
        if( maintransmittername != null ){
            item.setMaintransmittername(maintransmittername);
        }
        if( maintransmitterkey != null ){
            item.setMaintransmitterkey(maintransmitterkey);
        }
        if( sparetransmittername != null ){
            item.setSparetransmittername(sparetransmittername);
        }
        if( sparetransmitterkey != null ){
            item.setSparetransmitterkey(sparetransmitterkey);
        }
        if( maintransmitterpowertype != null ){
            item.setMaintransmitterpowertype(maintransmitterpowertype);
        }
        if( sparetransmitterpowertype != null ){
            item.setSparetransmitterpowertype(sparetransmitterpowertype);
        }
        if( ifmonitor != null ){
            item.setIfmonitor(ifmonitor);
        }
        if( equipmentmodel != null ){
            item.setEquipmentmodel(equipmentmodel);
        }
        if( valueself != null ){
            item.setValueself(valueself);
        }
       PageInfo<WebAequipmentgroup> list =  webAequipmentgroupService.getListWithPaging(pageNum, pageSize, sortItem, sortOrder,item);
       return new ResponseEntity<>(ResultModel.ok(list), HttpStatus.OK);

    }
}
